var url = window.location.href;
var sessionId = url.split("=")[1].split("&")[0];
var number =url.split("=")[2];
var agentShopID = url.split("=")[3];
// console.log(agentShopID);
// console.log(url);
var goodsID;
goods(sessionId);
function goods(sessionId) {
    $.post("http://www.brandt-beer.com/app/goods/getGoods",
        {GOODS_ID:number,SESSION_ID:sessionId},function (data) {
            console.log(data);
            var date = data.data;
            goodsID = date.GOODS_ID;
            // console.log(date.IMAGES1);
            document.getElementById("image1").src=date.IMAGES1;
            document.getElementById("image2").src=date.IMAGES2;
            document.getElementById("image3").src=date.IMAGES3;
            document.getElementById("goods_name").innerText=date.GOODS_NAME;
            document.getElementById("goods_title").innerText=date.GOODS_TITLE;
            document.getElementById("goods_subtitle").innerHTML=date.GOODS_SUBTITLE;
            document.getElementById("goods_content").innerHTML=date.CONTENT;
            document.getElementById("price").innerText=date.UNIT_PRICE;
            document.getElementById("salesSum").innerText=date.SALES_SUM;
            document.getElementById("details_img1").src=date.IMAGES1;
            document.getElementById("details_img2").src=date.IMAGES2;
            document.getElementById("contents").innerHTML=date.CONTENT;
        })
}
//加减数量
function red(){
    var sum = document.getElementById("sum").innerHTML;
    var red = sum-1;
//        alert(red);
    if (red>=0){
        $("#sum").empty().append(red);
    }
}
function adds() {
    var obtain = document.getElementById("sum").innerHTML;
    obtain++;
    $("#sum").empty().append(obtain);
}
//立即购买连接
function buy() {
    var num = document.getElementById("sum").innerText;
    var amount =document.getElementById("price").innerText;
    // console.log("商品ID："+goodsID+"\t 商铺ID："+agentShopID+"\t购买数量:"+num+"\t需要金额:"+num*amount);
    $.post("http://www.brandt-beer.com/app/goods/addOrders",
        {GOODS_ID:goodsID,SHOP_ID:number,SESSION_ID:sessionId,BUY_NUM:num,PAY_MONEY:num*amount},function (data) {
            // console.log(data);
            var date = data.data;
            var orders = date.ORDERS_NO;
            var payMoney=date.PAY_MONEY;
            $.post("http://www.brandt-beer.com/app/recharge/rechargeByTenpay",
                {ORDERS_NO:orders,PAY_MONEY:payMoney,SESSION_ID:sessionId}, function (data) {
                console.log(data);
                var request= data.resultCode;//00失败 01成功
                    if (request==00){
                        window.location.href="./payState/payFailure.html"
                    }else if(request==01){
                        window.location.href="./payState/paySuccessful.html?num="+num+"&goodsID="+number+"&sessionID="+sessionId;
                    }
                })
        });

}